package com.zzxx.mapper;


import com.zzxx.pojo.Member;
import com.zzxx.pojo.Orders;
import com.zzxx.pojo.Product;
import com.zzxx.pojo.Traveller;
import org.apache.ibatis.annotations.*;
import org.aspectj.weaver.ast.Or;

import java.util.List;

public interface OrdersMapper {
    @Results(id = "OrdersMap",value = {
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "orderNum",property = "orderNum"),
            @Result(column = "orderTime",property = "orderTime"),
            @Result(column = "orderStatus",property = "orderStatus"),
            @Result(column = "peopleCount",property = "peopleCount"),
            @Result(column = "payType",property = "payType"),
            @Result(column = "orderDesc",property = "orderDesc"),
            @Result(column = "productId",property = "product",one = @One(select = "com.zzxx.mapper.ProductMapper.findById")),
            @Result(column = "memberId",property = "member",one = @One(select = "com.zzxx.mapper.MemberMapper.findById")),
            @Result(column = "id",property = "travellers",many = @Many(select = "com.zzxx.mapper.TravellerMapper.findByOrderId"))
    }
    )
    @Select("select * from orders where id = #{id}")
    Orders findById(String id);

    @Update("update product set productDesc = #{productDesc},productPrice = #{productPrice} where id = #{id}")
    void updateProduct(Product product);

    @Update("update member set name = #{name},nickname = #{nickname},phoneNum = #{phoneNum},email = #{email} where id = #{id}")
    void updateMember(Member member);

    @Update("update orders set payType = #{payType} where id = #{id}")
    void updateOrders(Orders orders);

    @Update("update traveller set name = #{name},sex = #{sex},phoneNum = #{phoneNum},credentialsType = #{credentialsType},credentialsNum = #{credentialsNum} where id = #{id}")
    void updateTravellers(Traveller traveller);

    @Select("select * from orders")
    @ResultMap("OrdersMap")
    List<Orders> queryAll();

    @Update("delete from `orders` where id = #{id}")
    void deleteById(String id);


}
